package Two;

import java.util.*;

public class BuyBook {

    Map<Integer, Book> map = new HashMap();

    List buybook=new ArrayList();

    public void Enter() {

        Book book1 = new Book(1, "html+css", 10.0, 100);

        Book book2 = new Book(2, "javascript", 100.0, 1000);

        Book book3 = new Book(3, "java基础", 20.0, 200);

        Book book4 = new Book(4, "javaoo编程", 199.0, 2000);

        Book book5 = new Book(5, "数据库编程", 150.0, 1500);

        map.put(1, book1);

        map.put(2, book2);

        map.put(3, book3);

        map.put(4, book4);

        map.put(5, book5);
    }

    public void Static() {

        System.out.println("欢迎来到 xxxx 书店:");

        System.out.println("=====================================");

        System.out.println("编号\t书名\t\t\t价格\t当前库存");

        Set<Integer> s = map.keySet();

        for (Integer integer : s) {

            System.out.println(
                            map.get(integer).getId() + "\t" +
                            map.get(integer).getName() + "\t\t\t" +
                            map.get(integer).getMoney() + "\t" +
                            map.get(integer).getStock()
            );

        }

        System.out.println("1.购买  2.结账");

        System.out.println("=====================================================");

        Scanner scanner = new Scanner(System.in);

        int select = scanner.nextInt();

        switch (select) {

            case 1:

                buy();

                break;

            case 2:

                Settlement();

                break;
        }
    }


    public void buy(){

        Scanner scanner=new Scanner(System.in);

        System.out.println("===========================");

        System.out.println("请输入购买的书的编号");

        int num=scanner.nextInt();

        if (map.containsKey(num)){

            if (map.get(num).getStock()>0){

                buybook.add(map.get(num));

                map.get(num).setStock(map.get(num).getStock()-1);

                map.put(num,map.get(num));

                System.out.println("以为您添加到购物车，返回主菜单请输入0,输入1结账");

                int num1=scanner.nextInt();

                if (num1==0){

                    Static();
                }else if (num1==1) {

                    Settlement();

                }else {
                    System.out.println("您输入有误，已经为您返回到主菜单");

                    Static();
                }

            }else {

                System.out.println("您所输入的书籍库存不足");

                Static();
            }

        }else{

            System.out.println("您输入的书籍不存在");

            Static();
        }
    }


    public void Settlement(){

        System.out.println("============================================");

        System.out.println("显示购物车信息");

        System.out.println("编号\t书名\t   单格  \t购买数量\t   总和");

        

        for (Integer integer : s) {



        }

        System.out.println();
    }
}

